/**
 * Application
 *
 */

var express = require('express');
var ejs = require('ejs');
var config = require('./config');
//var csrf = require('./lib/csrf');

var app = express.createServer();
app.use(express.static(__dirname + '/public', {maxAge: 3600000 * 24 * 30}));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({
    secret: config.session_secret
}));

/*
app.use(csrf.check());
app.dynamicHelpers({
    csrf: csrf.token
});
*/

app.helpers({
    config: config
});


/**
 * Views settings
 */
app.set("view engine", "html");
app.set("views", __dirname + '/views');
app.register("html", ejs);

/**
 * Routing
 */
var faq = require('./controllers/faq');
app.get('/', faq.login);
app.get('/faq', faq.login);
app.get('/faq/login', faq.login);
app.post('/faq/login/do', faq.login_do);
app.get('/faq/question', faq.question);
app.post('/faq/question/new', faq.question_new);
app.get('/faq/:id/reply', faq.reply);
app.post('/faq/:id/reply/new', faq.reply_new);


// listen port
app.listen(config.port);

// start log
console.log(config.site_name + ' server start at http://localhost:' + config.port);


